<?php
class Axial_CommandDispatcher{
	//Controllernamn
	var $m_command;
	
	public function Axial_CommandDispatcher($a_command){
	
		$this->m_command = $a_command;
	}
	
	//Finns controllern? Ja = true osv. 
	public function IsController($a_controllerName){		
		if(file_exists("Controllers/".$a_controllerName."Controller.php")){
			return true;
		}else{
			return false;
		}
	}
	
	public function Dispatch(){		
		//Hämtar controllerobjektet
		$controllerName = $this->m_command->GetCommandName();
		
		if($controllerName == ""){
			$controllerName = "start";
		}elseif($this->IsController($controllerName)==false){
			$controllerName = "error";
		}
		
		//inkluderar controllern i projektet
		include('Controllers/'.$controllerName.'Controller.php');
			//Sparar undan controllernamnet i en variabel		
            $controllerClass = $controllerName."Controller";
			//Skapar en ny instans av controllerklassen
            $controller = new $controllerClass($this->m_command);		
            return $controller->Execute();
	}
}